package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.Planting;
import com.fsnbigdata.domain.PlantConservation;
import com.fsnbigdata.domain.QPlanting;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = PlantingRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = PlantingRepositoryCustom.class)
@Transactional(readOnly = true)
public class PlantingRepositoryImpl extends QueryDslRepositorySupportExt<Planting> implements PlantingRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    PlantingRepositoryImpl() {
        super(Planting.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String NOTES = "notes";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PLANTING_DATE = "plantingDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String QUANTITY = "quantity";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PLANTING_UNIT = "plantingUnit";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PLANT_CONSERVATION = "plantConservation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ALTITUDE = "altitude";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COORDINATE = "coordinate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String INTRO_NO = "introNo";

    /**
     * TODO Auto-generated method documentation
     *
     * @param plantConservation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<Planting> findByPlantConservation(PlantConservation plantConservation, GlobalSearch globalSearch, Pageable pageable) {
        QPlanting planting = QPlanting.planting;
        JPQLQuery<Planting> query = from(planting);
        Assert.notNull(plantConservation, "plantConservation is required");
        query.where(planting.plantConservation.eq(plantConservation));
        Path<?>[] paths = new Path<?>[] { planting.plantConservation, planting.introNo, planting.plantingUnit, planting.plantingDate, planting.coordinate, planting.altitude, planting.quantity, planting.notes };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(PLANT_CONSERVATION, planting.plantConservation).map(INTRO_NO, planting.introNo).map(PLANTING_UNIT, planting.plantingUnit).map(PLANTING_DATE, planting.plantingDate).map(COORDINATE, planting.coordinate).map(ALTITUDE, planting.altitude).map(QUANTITY, planting.quantity).map(NOTES, planting.notes);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, planting);
    }
}
